let webpack = require('webpack');
let HtmlWebpackPlugin = require('html-webpack-plugin');
let path = require('path');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

process.noDeprecation = true;

module.exports = {
    entry: {
        app: [path.join(__dirname, '../public/src/App.js')],
        common: ['react', 'react-dom', 'dva']
    },
    devtool: false,
    output: {
        path: path.join(__dirname, "../public/dist/"),
        filename: 'js/[name].[chunkhash:5].js',         // 打包后的文件名
        chunkFilename: "[name].[chunkhash:5].chunk.js",
        publicPath: '/'
    },
    externals: {
        // 'ramda': 'R',
        '@antv/data-set': 'DataSet'
    },
    resolve: {
        // require文件的时候不需要写后缀了，可以自动补全
        extensions: ['.js', '.jsx', '.css', '.scss']
    },
    module: {
        rules: [{
            test: /\.(js|jsx)$/,
            exclude: /(node_modules)/,
            use: [{
                loader: 'babel-loader',
                options: {
                    cacheDirectory: true,
                    presets: ['es2015', 'react'],
                    plugins: [
                        ["import", {libraryName: "antd", style: "css"}],
                        ["transform-runtime"],
                        ["transform-class-properties"],
                        ["transform-async-to-generator"],
                        ["transform-object-rest-spread"]
                    ]
                }
            }]},
            {test: /\.css$/, loader: 'style-loader!css-loader'},
            {
                test: /\.((ttf|eot|woff|svg)(\?t=[0-9]\.[0-9]\.[0-9]))|(ttf|eot|woff|svg)\??.*$/,
                loader: 'url-loader',
                options: {
                    limit: 10000,
                    name: 'iconfont/[name].[ext]'
                }
            },
            {
                test: /\.(png|jpg|gif)$/,
                loader: 'url-loader',
                options: {
                    limit: 10000,
                    name: 'images/[name].[ext]'
                }
            }]
    },
    plugins: [
        new webpack.optimize.CommonsChunkPlugin({
            filename: "js/common.[chunkhash:5].js",
            name: "common"
        }),     // 打包公共文件
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false
            }
        }),     // 压缩JS代码
        new HtmlWebpackPlugin({
            filename: '../dist/index.html',
            hash: true,
            template: 'public/src/views/index.ejs',

            // apiPath: -test
            authcenter: 'http://192.168.100.211:8080',
            imagent: 'http://192.168.100.211:8096',
            basedata: 'http://192.168.100.211:8082',

            //--pro
            // authcenter: "http://47.99.63.16:8083",
            // basedata: "http://47.99.63.16:8082",
            // imagent: "http://47.99.63.16:8081",
            // vipmc: "http://47.99.61.32:8080",

        }),
        new webpack.DefinePlugin({
            'process.env': {
                'NODE_ENV': '"production"'
            }
        }),
        new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /zh-cn/),
        new BundleAnalyzerPlugin()
    ]
};